package com.java.cas;

import java.util.concurrent.atomic.AtomicInteger;

/**
 * @author wangning
 * @date 2023/5/12 11:33
 */
public class CASDemo1 {

    public static void main(String[] args) {
        AtomicInteger atomicInteger = new AtomicInteger(5);//不写默认为0
        //expect：我在修改之前期望原来的值
        //update：我要修改的值
        atomicInteger.compareAndSet(5, 2019);
        System.out.println(atomicInteger.compareAndSet(5, 2019));
        System.out.println("atomicInteger = " + atomicInteger.get());
        System.out.println(atomicInteger.compareAndSet(5, 2020));
        System.out.println("atomicInteger = " + atomicInteger.get());
    }

}
